/*
 * Copyright (c) 2019 Nanjing Wind Information Co., Ltd. All Rights Reserved;
 * @Package wind.autotest.web
 * @version 1.0.0
 * @Date 2019年4月11日
 * @author jlliu.Farrior@wind.com.cn
 */
package wind.autotest.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import wind.autotest.pojo.TestTable;
import wind.autotest.service.frontend.TestTableService;
import wind.autotest.util.Page4Navigator;

/**
 * @Description: <类功能描述>
 * @author jlliu.Farrior@wind.com.cn
 * @Date 2019年4月11日 下午8:02:30
 * 
 */
@RestController
public class TableListController {

	@Autowired
	private TestTableService testTableService;

	@GetMapping("/tasks/{task_id}/tables")
    public Page4Navigator<TestTable> list(
    		@PathVariable("task_id") int task_id, 
    		@RequestParam(value = "start", defaultValue = "0") int start,
    		@RequestParam(value = "size", defaultValue = "5") int size) throws Exception {
        start = start<0 ? 0:start;
        Page4Navigator<TestTable> page =testTableService.list(task_id, start, size,5);
        return page;
    }

	@PostMapping("/tables")
	public Object add(@RequestBody TestTable bean) throws Exception {
		testTableService.add(bean);
		return bean;
	}
	
	@GetMapping("/tables/{id}")
	public TestTable get(@PathVariable("id") int id) throws Exception {
		TestTable bean = testTableService.get(id);
		return bean;
	}
	
	@PutMapping("/tables/{id}")
	public TestTable update(TestTable bean) throws Exception {
		
		testTableService.update(bean);
		
		return bean;
	}
	
	
	@DeleteMapping("/tables/{id}")
	public String delete(@PathVariable("id") int id, HttpServletRequest request)  throws Exception {
		testTableService.delete(id);
		return null;
	}
	
	
}
